package psd.core;

import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.CompilationUnit;

public class CodeParser {
	private CompilationUnitManager _context;
	private static int _currentKind;
	private static int _parseType;
	private static boolean _resolveBindings;

	public CodeParser() {
		_context = CompilationUnitManager.Instance();
		_resolveBindings = true;
		_currentKind = ASTParser.K_COMPILATION_UNIT;
		_parseType = AST.JLS3;
	}

	public CompilationUnit Parse() {
		ASTParser parser = ASTParser.newParser(get_parseType());
		parser.setKind(get_currentKind());
		parser.setSource(_context.get_currentCompilationUnit());
		if (is_resolveBindings())
			parser.setResolveBindings(true);
		return (CompilationUnit) parser.createAST(null); // parse
	}
	
	public int get_currentKind() {
		return _currentKind;
	}

	public void set_currentKind(int currentKind) {
		_currentKind = currentKind;
	}

	public int get_parseType() {
		return _parseType;
	}

	public void set_parseType(int parseType) {
		_parseType = parseType;
	}

	public void set_resolveBindings(boolean _resolveBindings) {
		this._resolveBindings = _resolveBindings;
	}

	public boolean is_resolveBindings() {
		return _resolveBindings;
	}
}
